<template>
  <div class="siteAndRailWrap">
    <div class="pageTableInner">
      <div class="infoSearchWrap">
        <div class="infoSearchOne">
          <el-row :gutter="20">
            <el-col :span="5">
              <div class="searchWrap">
                <span class="searchFont">站点类型:</span>
                <span class="searchInputFont">
                    <el-select v-model="searchInfo.areaType" @change="searchRowsInfo" size="mini" clearable placeholder="全部">
                       <el-option
                         v-for="item in options"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value">
                        </el-option>
                    </el-select>
                </span>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="searchWrap">
                <span class="searchFont">行政区域:</span>
                <span class="searchInputFont" style="width: 38%;">
                  <el-select v-model="searchInfo.district" :disabled="$store.state.userInfo.regionId?true:false" @change="changeDistrict(searchInfo.district)" size="mini"
                             clearable placeholder="行政区">
                    <el-option
                      v-for="item in $store.state.districtData"
                      :key="item.id"
                      :label="item.regionName"
                      :value="item.id">
                    </el-option>
                  </el-select>
                </span>
                <span class="searchInputFont" style="width: 38%;">
                    <el-select v-model="searchInfo.street" @change="searchRowsInfo" size="mini" clearable placeholder="街道">
                      <el-option
                        v-for="item in streetData"
                        :key="item.id"
                        :label="item.regionName"
                        :value="item.id">
                      </el-option>
                    </el-select>
                 </span>
              </div>
            </el-col>
            <el-col :span="5">
              <div class="searchWrap">
                <span class="searchFont">站点名称:</span>
                <span class="searchInputFont">
                    <el-input clearable size="mini" v-model="searchInfo.areaName" @change="searchRowsInfo" auto-complete="off" placeholder="站点名称"></el-input>
                </span>
              </div>

            </el-col>
            <el-col v-show="searchInfo.areaType==1" :span="4">
              <div class="searchWrap">
                <span class="searchFont">围栏类型:</span>
                <span class="searchInputFont" style="width: 60%;">
                    <el-select v-model="searchInfo.areaAttribute" @change="searchRowsInfo" size="mini" clearable placeholder="全部">
                       <el-option
                         v-for="item in options1"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value">
                        </el-option>
                    </el-select>
                </span>
              </div>
            </el-col>
            <div style="float: right;margin-right: 10px;">
              <el-button type="primary" size="mini" @click="searchRowsInfo()">查询</el-button>
            </div>
          </el-row>
        </div>
      </div>
      <div class="tableContainer">
        <div class="tableInner">
          <el-table
            ref="multipleTable"
            :data="rows"
            stripe
            :height="tableHeight"
            tooltip-effect="dark"
            style="width: 100%"
          >
            <el-table-column
              label="站点名称"
              prop="areaName"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              label="站点类型"
              prop="areaType"
              show-overflow-tooltip>
              <template slot-scope="scope">
                {{scope.row.areaType ==0 ? "智能站点" : scope.row.areaType == 1 ? "电子围栏" : ""}}

              </template>
            </el-table-column>
            <el-table-column
              label="站点编号"
              prop="areaNo"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              label="行政区"
              prop="districtName"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              label="街道"
              prop="streetName"
            >
            </el-table-column>
            <el-table-column
              label="所属企业"
              prop="enterpriseName"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              label="停放容量"
              prop="volume"
              show-overflow-tooltip>

            </el-table-column>
            <el-table-column
              label="停放数量"
              prop="parkNum"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              label="站点地址"
              prop="address"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              label="站点状态"
              prop="areaStatus"
              show-overflow-tooltip>
              <template slot-scope="scope">
                {{scope.row.areaStatus == 0 ? "正常" : scope.row.areaStatus == 1 ? "停用" : ""}}
              </template>
            </el-table-column>
            <el-table-column
              v-if="searchInfo.areaType==1"
              label="围栏类型"
              prop="areaAttribute"
              show-overflow-tooltip>
              <template slot-scope="scope">
                {{scope.row.areaAttribute == 0 ? "普通" : scope.row.areaAttribute == 1 ? "紧急" : ""}}
              </template>
            </el-table-column>
            <el-table-column
              prop="createTime"
              label="创建时间"
              :formatter="dateFormat"
              show-overflow-tooltip>
            </el-table-column>
          </el-table>
        </div>
        <div class="paginationWrap" >
          <el-row :gutter="10">
            <el-col :span="13" :offset="9">
              <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[10, 30, 50, 100,200]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="count">
              </el-pagination>
            </el-col>
          </el-row>
        </div>

      </div>
    </div>
  </div>
</template>

<script>


  export default {
    props: [],
    data(){
      return {
        options: [
          {
            value: '0',
            label: '智能站点'
          }, {
            value: '1',
            label: '电子围栏'
          },],
        options1: [
          {
            value: '0',
            label: '普通'
          }, {
            value: '1',
            label: '紧急'
          },],
        streetData: [],
        rows: [],
        pageSize: 10,
        count: 0,
        currentPage: 1,
        tableHeight: 400,
        checkInfo: {},
        searchInfo: {
          street: "",
          district: this.$store.state.userInfo.regionId,
          areaAttribute: "",
          areaType: "",
          areaName: "",
          sortType: "",
          asc: "true"
        },
      }
    },
    components: {},
    created(){
      this.searchRowsInfo()
      setTimeout(()=>{
        if(this.$store.state.userInfo.regionId){this.changeDistrict(this.searchInfo.district)}
      },500)
    },
    mounted(){
      this.$nextTick(() => {
        //表格高度
        this.tableHeight = document.querySelector(".siteAndRailWrap").clientHeight - 160
      })
    },

    methods: {
      dateFormat(row, column){
        return this.dtime(row[column.property]).format('YYYY-MM-DD HH:mm:ss')
      },
      pushAndGet(row){
        this.checkInfo=row
        this.$router.push("/parkingArea/parkSet")
      },
      handleDelete(row){
        this.$confirm('确认删除用户 “' + row.areaName + '” , 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.axios.post(process.env.API_HOST + `/area/deleteGovArea`,{id:row.id})
            .then(response => {
              const result = response.data
              if (result.code === 200) {
                this.searchRowsInfo()
                this.$message({
                  type: 'success',
                  message: '删除成功!'
                });
              }
            })

          //删除当前
        }).catch(() => {

        });
      },
      //获取街道
      changeDistrict(district){
        this.searchRowsInfo()
        if(!district){
          this.searchInfo.street=""
          this.streetData=[]
          return
        }
        this.axios.post(process.env.API_HOST + '/common/selectRegion',{parentId:district})
          .then(response => {
            const result = response.data
            if (result.code == 200) {
              this.streetData = result.result
            }
          })
      },
      //排序
      sortChange(a) {
        if (a.column) {
          if (a.column.label == "电子标签") {
            this.searchInfo.asc = !this.searchInfo.asc
            this.searchInfo.sortType = "labelNo"
            this.searchRowsInfo()
          } else if (a.column.label == "车辆编号") {
            this.searchInfo.asc = !this.searchInfo.asc
            this.searchInfo.sortType = "vehicleNo"
            this.searchRowsInfo()
          } else {
            this.searchInfo.sortType = a.prop
            this.searchRowsInfo()
          }
        } else {
          this.searchInfo.asc = "true", this.searchInfo.sortType = ""
        }
      },


      //获取所有信息
      searchRowsInfo(val){
        val?"":this.currentPage=1
        this.axios.post(process.env.API_HOST + `/facilities/selectAreaGrid`, {
        page: this.currentPage,
        rows: this.pageSize,
        areaName: this.searchInfo.areaName,
        district: this.searchInfo.district,
        street: this.searchInfo.street,
        areaType: this.searchInfo.areaType,
        areaAttribute: this.searchInfo.areaAttribute,
        })
          .then(response => {
            const result = response.data
            if(result.code==200){
              this.rows = result.rows
              this.count = result.total;
            }
          })
      },
      handleSizeChange(val) {
        this.pageSize = val
        this.searchRowsInfo()
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        this.searchRowsInfo(val)
      },
    },
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">
  @import "../../../common/stylus/mixin.styl"
  .siteAndRailWrap
    page()
</style>
